﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using AutoMapper;
using TheNorthStar.Api.Requests;
using TheNorthStar.Domain;

namespace TheNorthStar.Web.Application.Mappings
{
    public class BookingMaps
    {
        public static void Configure()
        {
            Mapper.CreateMap<Booking, Models.Json.Booking>();
            Mapper.CreateMap<NewBooking, Booking>()
                .ForMember(dest=>dest.PickupUnit, opt=>opt.MapFrom(src=>src.UnitNumber))
                .ForMember(dest => dest.PickupStreetNumber, opt => opt.MapFrom(src => src.StreetNumber))
                .ForMember(dest => dest.PickupStreet, opt => opt.MapFrom(src => src.Street))
                .ForMember(dest => dest.PickupStreetType, opt => opt.MapFrom(src => src.StreetType))
                .ForMember(dest => dest.PickupSuburb, opt => opt.MapFrom(src => src.Suburb))
                .ForMember(dest => dest.Latitude, opt => opt.MapFrom(src => (decimal)src.Lat))
                .ForMember(dest => dest.Longitude, opt => opt.MapFrom(src => (decimal)src.Lng));

            Mapper.CreateMap<Booking, Api.Results.Booking>()
                .ForMember(dest => dest.DriverName, opt => opt.MapFrom(x => (x.Driver != null ? string.Format("{0} {1}", x.Driver.FirstName,x.Driver.LastName) : string.Empty)))
                                                      
                .ForMember(dest => dest.DriverPhoneNumber,
                           opt => opt.MapFrom(x => (x.Driver != null ? x.Driver.PhoneNumber : string.Empty)))
                .ForMember(dest => dest.Latitude,
                           opt => opt.MapFrom(x => (x.Driver != null ? x.Driver.LastKnownLatitude : 0)))

                .ForMember(dest => dest.Longitude,
                           opt => opt.MapFrom(x => (x.Driver != null ? x.Driver.LastKnownLongitude : 0)))
                .ForMember(dest => dest.PassengerPhoneNumber, opt => opt.MapFrom(src => src.Customer.PhoneNumber))
                .ForMember(dest => dest.PickupSuburb, opt => opt.MapFrom(src => src.PickupSuburb))
                .ForMember(dest => dest.Address, opt => opt.MapFrom(src => string.Format("{0} {1} {2} {3}, {4}",src.PickupUnit ,src.PickupStreetNumber,src.PickupStreet,src.PickupStreetType,src.PickupSuburb)));

                 
        }
    }
}